package 机试题16年;

/**
 * Created by hest0 on 2017/4/20.
 */
public class 之字形打印矩阵 {
    public static void main(String[] args) {

    }

    public static class Printer {
        public int[] printMatrix(int[][] mat, int n, int m) {
            int[] a = new int[n * m];
            int idx = 0;
            for (int i = 0; i < n; i++) {
                int[] row = mat[i];
                if (i % 2 == 0) {
                    for (int j = 0; j < row.length; j++) {
                        a[idx++] = row[j];
                    }
                } else {
                    for (int j = row.length - 1; j >= 0; j--) {
                        a[idx++] = row[j];
                    }
                }
            }
            return a;
        }
    }

}
